package com.infore.airsupervise.biz.impl;

import com.infore.airsupervise.app.Constants;
import com.infore.airsupervise.app.MsgConst;
import com.infore.airsupervise.bean.StationGridE;
import com.infore.airsupervise.bean.UserE;
import com.infore.airsupervise.biz.UserAndGridBiz;
import com.infore.airsupervise.http.BaseResponse;
import com.infore.airsupervise.http.HttpAPI;
import com.infore.airsupervise.http.HttpCallBack;
import com.infore.airsupervise.http.HttpUtil;
import com.infore.airsupervise.http.OnServerResponseListener;
import com.infore.airsupervise.utils.JSONUtil;

import java.util.Collections;
import java.util.List;

import retrofit2.Call;

/**
 * @features:
 * @author: WuTao
 * @date: 2017/4/15 13:49
 */
public class UserAndGridBizImpl implements UserAndGridBiz{
    @Override
    public Call<BaseResponse> getAllPsonRequest(String userId, final OnServerResponseListener<List<UserE>> listener) {

        Call<BaseResponse> call = HttpUtil.getHttpService().postParams(HttpAPI.GET_ALLPERSON_LIST, Collections.EMPTY_MAP);
        call.enqueue( new HttpCallBack() {
            @Override
            public void onSuccess(int operationCode, BaseResponse response) {
                super.onSuccess(operationCode, response);
                List<UserE> result = JSONUtil.parseList(response.getData(), Constants.RESPONSE_BEAN_LIST_KEY,UserE.class);
                listener.onSucceed(result, MsgConst.GET_DATA_SUCCESS);
            }

            @Override
            public void onFailed(int operationCode, String desc) {
                super.onFailed(operationCode, desc);
                listener.onFailed(operationCode,MsgConst.GET_DATA_FAILED,desc);
            }

            @Override
            public void onException(int errorCode, String title, String desc) {
                super.onException(errorCode, title, desc);
                listener.onFailed(errorCode, title, desc);
            }
        });
        return call;
    }

    @Override
    public Call<BaseResponse> getGridInfoRequest(String userId, final OnServerResponseListener<StationGridE> listener) {
        Call<BaseResponse> call = HttpUtil.getHttpService().postParams(HttpAPI.GET_GRID_LIST,Collections.EMPTY_MAP);
        call.enqueue( new HttpCallBack() {
            @Override
            public void onSuccess(int operationCode, BaseResponse response) {
                super.onSuccess(operationCode, response);
                StationGridE  gridE = JSONUtil.parseBean(response.getData(),Constants.RESPONSE_BEAN_KEY,StationGridE.class);
                listener.onSucceed(gridE,MsgConst.GET_DATA_SUCCESS);
            }

            @Override
            public void onFailed(int operationCode, String desc) {
                super.onFailed(operationCode, desc);
                listener.onFailed(operationCode,MsgConst.GET_DATA_FAILED,desc);
            }

            @Override
            public void onException(int errorCode, String title, String desc) {
                super.onException(errorCode, title, desc);
                listener.onFailed(errorCode, title, desc);
            }
        });
        return null;
    }


}
